fix: wire document search command centre to live /api/search#460
Conversation
The /documents/search "Search command centre" filtered a hardcoded fixture array, so real queries (e.g. "lithium") returned "No documents match" even though the corpus is indexed. Replace the fixtures + client filter in MasterDocumentSearch with a POST /api/search (mode: documents) fetch: map documentMatches + result source_metadata into the existing table and mobile cards (status, version, evidence counts, relevance, snippet), add loading/error/empty states, and pass the auth header so signed-in users get owner-scoped results and anonymous users get the public corpus. Open links now target the real document viewer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe master document search now uses authenticated ChangesLive document search
Readiness checklist metadata
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant SearchUI
participant SearchAPI
participant ResultRows
participant ResultCards
SearchUI->>SearchAPI: POST search query with auth headers
SearchAPI-->>SearchUI: return document matches
SearchUI->>ResultRows: normalize status, dates, counts, relevance, and href
ResultRows-->>ResultCards: render filtered rows
Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error, 1 warning)
✅ Passed checks (9 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67f5bb2744
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Addresses a Codex P2 review finding: formatDateish parsed date-only ISO values (e.g. "2026-07-10") as UTC midnight, then formatted them in local time, so review/publication dates rendered one day early in negative-offset timezones (e.g. America/New_York). Format in UTC and pin en-GB day-month-year (matching the app's existing date style). Export formatDateish and add a focused regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The command centre now renders live search results instead of the removed in-file fixtures, so the smoke test's assertions (fixture title, "Table evidence" label, and the fixture-only "Evidence" deep-link) no longer match. Assert the mocked API response the page actually renders: the "Synthetic lithium monitoring protocol" match, real "Tables 1" evidence count, and the document-viewer link. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/ui-smoke.spec.ts`:
- Around line 2077-2082: Add assertions in the document-results test near the
existing checks for “Synthetic lithium monitoring protocol” to verify the “Open
document” link exists and targets the expected document-viewer URL, including
the correct page and chunk query parameters from the mocked search result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c085b0e8-b122-471f-b165-00932a8b076c
📒 Files selected for processing (3)
src/components/master-document-flow-mockups.tsxtests/master-document-flow-date.test.tstests/ui-smoke.spec.ts
✅ Files skipped from review due to trivial changes (1)
- tests/master-document-flow-date.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/components/master-document-flow-mockups.tsx
| // The command centre now renders live /api/search results (see mockDemoApi), not the | ||
| // former in-file fixtures: the mocked lithium query returns "Synthetic lithium monitoring | ||
| // protocol" with real table/image evidence counts and links to the document viewer. | ||
| await expect(documentResults).toContainText("Synthetic lithium monitoring protocol"); | ||
| await expect(documentResults).toContainText("Best match"); | ||
| await expect(documentResults).toContainText("Table evidence"); | ||
| await expect(documentResults).toContainText("Tables 1"); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Cover the document-viewer link contract.
These assertions verify the result text and evidence count, but not the “Open document” link or its page/chunk parameters. A regression could therefore pass while opening the wrong document location.
Suggested test coverage
await expect(documentResults).toContainText("Tables 1");
+const openDocumentLink = documentResults.getByRole("link", { name: "Open document" });
+await expect(openDocumentLink).toBeVisible();
+await expect(openDocumentLink).toHaveAttribute(
+ "href",
+ /\/documents\/[^?]+\?page=\d+(&chunk=[^&]+)?$/,
+);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // The command centre now renders live /api/search results (see mockDemoApi), not the | |
| // former in-file fixtures: the mocked lithium query returns "Synthetic lithium monitoring | |
| // protocol" with real table/image evidence counts and links to the document viewer. | |
| await expect(documentResults).toContainText("Synthetic lithium monitoring protocol"); | |
| await expect(documentResults).toContainText("Best match"); | |
| await expect(documentResults).toContainText("Table evidence"); | |
| await expect(documentResults).toContainText("Tables 1"); | |
| // The command centre now renders live /api/search results (see mockDemoApi), not the | |
| // former in-file fixtures: the mocked lithium query returns "Synthetic lithium monitoring | |
| // protocol" with real table/image evidence counts and links to the document viewer. | |
| await expect(documentResults).toContainText("Synthetic lithium monitoring protocol"); | |
| await expect(documentResults).toContainText("Best match"); | |
| await expect(documentResults).toContainText("Tables 1"); | |
| const openDocumentLink = documentResults.getByRole("link", { name: "Open document" }); | |
| await expect(openDocumentLink).toBeVisible(); | |
| await expect(openDocumentLink).toHaveAttribute( | |
| "href", | |
| /\/documents\/[^?]+\?page=\d+(&chunk=[^&]+)?$/, | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/ui-smoke.spec.ts` around lines 2077 - 2082, Add assertions in the
document-results test near the existing checks for “Synthetic lithium monitoring
protocol” to verify the “Open document” link exists and targets the expected
document-viewer URL, including the correct page and chunk query parameters from
the mocked search result.
Summary
/documents/search"Search command centre" filtered a hardcoded fixture array of 5 demo documents, so real queries (e.g. "lithium") returned "No documents match" even though the corpus is indexed — while the "Also in your library" panel (a different data source) did show lithium, making the contradiction obvious.MasterDocumentSearchnow queries the live retrieval pipeline viaPOST /api/search(mode: "documents") instead of filtering fixtures. ResponsedocumentMatches+results[].source_metadataare mapped into the existing table and mobile cards (source, version, status pill, real table/image evidence counts, relevance %, page, snippet).useAuthSession) is forwarded so signed-in users get owner-scoped results and anonymous users get the public corpus./documents/[id]?page=&chunk=) instead of the fixture reader.evidenceForType,evidenceLabel,evidenceTypeLabel,EvidenceTypeIcon). The fixture array and the reader/evidence mockup pages are intentionally left unchanged (out of scope).Chose
POST /api/search(modedocuments) over the thinGET /api/search/universaltypeahead endpoint because this table renders status/version/evidence-counts that universal doesn't carry — it's the same endpoint the app's existing document search UI uses. The Sources/Tables/Images tabs filter real evidence signals; Quotes/Related fall back to the full match list (the API doesn't tag those per document).Verification
npm run verify:cheap— typecheck ✅, lint ✅, 1410 tests pass. One caveat: the sole failure,tests/public-access-deep.test.ts(operator-route auth, unrelated to this diff), is a 15s-default-timeout hit while transforming heavy route modules under this worktree's junctionednode_modules; it passes cleanly at--testTimeout=90000(32s). Not a logic failure and green on CI's faster runners.npm run verify:ui— not runnable locally: this worktree'snode_modulesis a junction, which Turbopack'sturbopack.rootcheck rejects, so the dev server can't start here. The requiredui-smokeCI check (Chromium) is the authoritative UI gate and is exercised on this branch.npm run verify:release— not a release/handoff.npm run format:check— the changed file is prettier-clean. The local run's non-zero exit was two untouched files (CLAUDE.md,.claude/settings.json) showing CRLF in a Windows working tree; both are LF in the index and byte-identical toorigin/main, so CI (LF) passes.npm run eval:retrieval:quality— N/A: no retrieval, ranking, selection, chunking, or scoring behavior changed. This is a client component that calls the existing/api/searchendpoint; server retrieval logic is untouched.npm run eval:rag/eval:quality— N/A: answer generation / synthesis prompt unchanged.npm run check:production-readiness— N/A: no server-side governance, privacy, environment, Supabase, or access-control change; client display only.npm run check:deployment-readiness— N/A: no deployment/startup change.Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy) — no config change./api/search.Notes
src/components/master-document-flow-mockups.tsx.🤖 Generated with Claude Code